package com.springboot.demo.web;
import org.springframework.web.servlet.HandlerInterceptor;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginInterceptor implements HandlerInterceptor {//简易的登录拦截，防止用户直接登录http://localhost:9000/welcome
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        Object temp = request.getSession().getAttribute("judge");
        if (null == temp || !(temp instanceof String)) {
            response.sendRedirect("/readerlogin");
            return false;
        }
        return true;
    }
}
